import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Inject, Injectable } from '@nestjs/common';
import { Cache } from '@nestjs/cache-manager';
import { RedisClientType } from 'redis';
@Injectable()
export class RedisService {
  constructor(
    @Inject(CACHE_MANAGER)
    private readonly cacheManager: Cache,
  ) {}
  // 获取
  async get<T>(key: string): Promise<T | null> {
    return await this.cacheManager.get(key);
  }
  // 设置
  async set(key: string, value: any, ttl?: number): Promise<void> {
    return await this.cacheManager.set(key, value, ttl);
  }
  // 删除
  async del(key: string): Promise<boolean> {
    return await this.cacheManager.del(key);
  }
}
